package com.chinasoft.ssm.advice;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class ClearSpaceAdvice {

    // 定义 切点
    @Pointcut("execution(* com.chinasoft.ssm.service.*Service.*(..))")
    private void ptService() {
        // null;
    }

    @Around("ptService()")
    public Object clearSpace(ProceedingJoinPoint jp) throws Throwable {
//        System.out.println("清理数据库表格...");
        Object[] args = jp.getArgs();
        for (Object arg : args) {
            System.out.println("参数： " + arg);
        }
        for(int i = 0; i < args.length; i++) {
            if (args[i] instanceof String) {
//                args[i].getClass().equals(String.class)
                System.out.println(args[i] + " 是 字符串");
                // 去掉字符串前面和后面的空格
                args[i] = args[i].toString().trim();
            } else {
                System.out.println(args[i] + "不 是 字符串");
            }
        }
        return jp.proceed(args);
    }
}
